<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2017/5/27
 * Time: 15:51
 */

namespace app\admin\controller;
use think\Controller;
use think\Response;
use think\Session;
use think\Request;

class Base extends Controller
{
    /**
     * 用户ID
     * @access protected
     * @var int
     */
    protected $aid = 0;
    /*
     * 登录用户信息
     * @access protected
     * @var null|array
     * */
    protected $admin=null;
    /*
     * 跳转链接
     * @var string
     * */
    protected $goto='';


    public function _initialize()
    {
        $this->_initAdmin();
    }


    /*
     * 初始化用户信息
     * */
    protected function _initAdmin(){
        $this->admin = Session::get('AdminInfo');
        if(!empty($this->admin)){
            $this->aid = $this->admin['id'];
        }
    }

    /*
     * 表单数据获取并验证
     * @param   $valid
     * @param array $message
     * @return mixed
     * */
    protected function formDate($valid,$message=[]){
        $data = $this->request->post();
        $result = $this->validate($data,$valid,$message);
        if($result == true){
            if(isset($data['goto'])){
                $this->goto =$data['goto'];
            }
            return $data;
        }else{
            return $result;
        }
    }
    /*
     * 获取IP地址
     * */
    protected function getIp(){
        if (getenv('HTTP_CLIENT_IP')) {
            $ip = getenv('HTTP_CLIENT_IP');
        }
        elseif (getenv('HTTP_X_FORWARDED_FOR')) {
            $ip = getenv('HTTP_X_FORWARDED_FOR');
        }
        elseif (getenv('HTTP_X_FORWARDED')) {
            $ip = getenv('HTTP_X_FORWARDED');
        }
        elseif (getenv('HTTP_FORWARDED_FOR')) {
            $ip = getenv('HTTP_FORWARDED_FOR');
        }
        elseif (getenv('HTTP_FORWARDED')) {
            $ip = getenv('HTTP_FORWARDED');
        }
        else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        return $ip;
    }






}